<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="选择年度：">
          <el-select v-model="listPram.year" placeholder="年度" style="width: 100%">
            <el-option
              v-for="(item,index) in yearList"
              :key="index"
              :label="item"
              :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="完成情况：" prop="completionStatus">
          <el-select v-model="listPram.completionStatus" placeholder="请选择">
            <el-option
              v-for="item in statusList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="handlerOpenEdit(0)" v-hasPermi="['admin:year:task:save']">导入</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" v-loading="loading" size="mini"  @sort-change="handleSortChange"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column prop="number" label="序号" width="50" sortable="custom"/>
        <el-table-column label="类别" prop="type" min-width="80"/>
        <el-table-column label="业务领域" prop="businessAreas" min-width="80"/>
        <el-table-column label="具体工作计划">
        <el-table-column  prop="planOne" min-width="120"/>
        <el-table-column  prop="planTwo" min-width="120"/>
        </el-table-column>
        <el-table-column label="预期成果" prop="expectedResults" min-width="120"/>
        <el-table-column label="完成时限" prop="completionDeadline" min-width="120"/>
        <el-table-column label="责任单位" prop="responsibleUnit" min-width="120"/>
        <el-table-column label="责任人" prop="responsiblePerson" min-width="120"/>
        <el-table-column label="完成情况" prop="completionStatus" min-width="80">
          <template slot-scope="scope">
            <div v-if="scope.row.completionStatus === '未开始'" style="color: #e03e2d">未开始</div>
            <div v-if="scope.row.completionStatus === '进行中'" style="color: #022cff">进行中</div>
            <div v-if="scope.row.completionStatus === '已完成'" style="color: #11ec09">已完成</div>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark" min-width="120"/>
        <el-table-column label="年度" prop="year" min-width="60"/>
        <el-table-column label="操作" min-width="80" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" type="primary" size="mini" @click="handlerOpenEdit(1,scope.row)" v-hasPermi="['admin:year:task:info']">完成情况</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialogConfig.visible"
      :title="editDialogConfig.isCreate === 0? '创建':'编辑'"
      destroy-on-close
      :close-on-click-modal="false"
      width="700px"
    >
      <edit
        v-if="editDialogConfig.visible"
        :is-create="editDialogConfig.isCreate"
        :edit-data="editDialogConfig.editData"
        :all-tree-list="treeList"
        :all-category-data="categoryData"

        @hideEditDialog="hideEditDialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import * as taskApi from '@/api/task.js'
import * as roleApi from '@/api/role.js'
import edit from './edit'
import { checkPermi } from '@/utils/permission'
import * as selfUtil from '@/utils/ZBKJIutil' // 权限判断函数

export default {
  // name: "index"
  components: { edit },
  data() {
    return {
      statusList: [{ id: 1, name: '未开始' }, { id: 2, name: '进行中' }, { id: 3, name: '已完成' }],
      constants: this.$constants,
      loading: false,
      listData: {
        list: [],
        count:0
      },
      listPram: {
        year: null,
        page: 1,
        limit: this.$constants.page.limit[0]
      },
      year: null,
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editData: {}
      },
      yearList: [],
      categoryData: {},
      treeList: []
    }
  },
  mounted() {
    this.initYearList()
    this.handleGetTaskList()
  },
  methods: {
    handleSortChange(c) {
      const order = c.order;
      if (order == null || order == 'ascending') {
        this.listPram.sortType = 2;
      } else {
        this.listPram.sortType = 1;
      }
      this.handleGetTaskList();
    },
    initYearList() {
      let date = new Date()
      let year = date.getFullYear()
      for (let i = 0; i < 10; i++) {
        this.yearList.push(year - i)
      }
      this.year = year
      this.listPram.year = year
    },
    checkPermi,
    handleSearch() {
      this.listPram.page = 1
      this.handleGetTaskList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetTaskList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetTaskList()
    },
    handlerOpenDel(rowData) {
      this.$confirm('确认删除当前数据').then(() => {
        const _pram = { id: rowData.id }
        taskApi.typeDel(_pram).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetTaskList()
        })
      })
    },

    handleGetTaskList() {
      taskApi.yearList(this.listPram).then(data => {
        this.listData = data
      })
    },
    handlerOpenEdit(isCreate, editDate) {
      this.editDialogConfig.editData = editDate
      this.editDialogConfig.isCreate = isCreate
      this.editDialogConfig.visible = true
    },
    hideEditDialog() {
      this.editDialogConfig.visible = false
      this.handleGetTaskList()
    },
    resetQuery() {
      this.listPram.year = this.year
      this.listPram.completionStatus = null
      this.handleGetTaskList()
    }
  }
}
</script>

<style scoped>

</style>
